package org.smr.dev.web;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

 import jakarta.annotation.Resource;
import org.apache.commons.collections.MapUtils;
import org.smr.dev.datatype.ColumnTypeEnum;
import org.smr.dev.javabean.JavaBeanCodeGenerator;
import org.smr.dev.model.TableMeta;
import org.smr.dev.service.TableMeteService;
import org.smr.dev.utils.CodeConst;
import org.smr.dev.utils.FileUtils;
import org.smr.dev.utils.NamesUtils;
import org.smr.dev.utils.StringUtils;
import org.smr.dev.vo.EntityDefine;
import org.smr.dev.vo.Module;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("entity")
public class EntitiesController {

    @Resource
    private TableMeteService tableMeteService;

    @Value("${smr.project.path}")
    private String projectPath;


    @RequestMapping("index")
    public String build(String tableName, String tableSchema, Model model) {

        String entityName = NamesUtils.tableName2EntityName(tableName);
        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName, tableSchema);
        CodeConst.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        CodeConst.put(CodeConst.TABLE_NAME_VARIABLE, tableName);

        model.addAttribute("tableName", tableName);
        model.addAttribute("list", tableMetaList);
        return "/column/entity-index";
    }

    @ResponseBody
    @RequestMapping("saveEntity")
    public Map saveEntity(@RequestBody List<TableMeta> params, String tableName) {

        String entityName = NamesUtils.tableName2EntityName(tableName);
        EntityDefine ed = new EntityDefine();
        ed.setTableName(tableName);
        ed.setName(entityName);
        ed.setEntityProterties(params);
        Map message = new HashMap();

        for (TableMeta tableMeta : params) {

            tableMeta.setMethodName(NamesUtils.getFirstUpperCaseName(tableMeta.getPropertyName()));

        }
        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        ed.setModuleName(module.getName());
        module.addEntityDefine(ed);
        message.put("code", 1);
        message.put("msg", "success");
        return message;
    }

    @ResponseBody
    @RequestMapping("genModule")
    public void genModule() {

        String projectPath = (String) CodeConst.get(CodeConst.PROJECT_DIR);
        String projectName = (String) CodeConst.get(CodeConst.PROJECT_NAME);

        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        List<EntityDefine> entityDefineList = module.getEntityDefineList();
        CodeConst.put(CodeConst.MODULE_DEFINE, module);

        createProject(projectName);
        for (EntityDefine ed : entityDefineList) {

            genPage(ed, projectName, projectPath);
            genVue3Page(ed, projectName, projectPath);
            genModel(ed, projectName, projectPath);
            genVO(ed, projectName, projectPath);

            genDao(ed, projectName, projectPath);
            getService(ed, projectName, projectPath);

            genMicroService(ed, projectName, projectPath);
            genMicroServiceClient(ed, projectName, projectPath);
            genFacade(ed, projectName, projectPath);
            genServiceImpl(ed, projectName, projectPath);
            genController(ed, projectName, projectPath);
        }

    }

    @ResponseBody
    @RequestMapping("genDDDModule")
    public void genDDDModule() {

        String projectPath = (String) CodeConst.get(CodeConst.PROJECT_DIR);
        String projectName = (String) CodeConst.get(CodeConst.PROJECT_NAME);

        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        List<EntityDefine> entityDefineList = module.getEntityDefineList();
        CodeConst.put(CodeConst.MODULE_DEFINE, module);

        createProject(projectName);
        for (EntityDefine ed : entityDefineList) {

            genPage(ed, projectName, projectPath);
            genVue3Page(ed, projectName, projectPath);
            genDomain(ed, projectName, projectPath);
            genVO(ed, projectName, projectPath);
            genCommon(ed, projectName, projectPath);

            genInfrastructure(ed, projectName, projectPath);

            genRepository(ed, projectName, projectPath);
            getDDDService(ed, projectName, projectPath);
            genDDDMicroService(ed, projectName, projectPath);
            genDDDMicroServiceClient(ed, projectName, projectPath);
            genDDDServiceClient(ed, projectName, projectPath);

            genDDDFacade(ed, projectName, projectPath);
            genDDDServiceImpl(ed, projectName, projectPath);

            getDDDRepository(ed, projectName, projectPath);
            genDDDRepositoryImpl(ed, projectName, projectPath);

            genDDDController(ed, projectName, projectPath);
        }

    }


    @ResponseBody
    @RequestMapping("gen")
    public void genEntityCode() {

        String tableName = "t_organ_info";
        String tableSchema = "auth_center";
        String entityName = NamesUtils.tableName2EntityName(tableName);
        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName, tableSchema);

        Map<String, Object> daoVar = new HashMap<>();

        daoVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        daoVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);

        Map<String, Object> modelVar = new HashMap<>();
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);


        JavaBeanCodeGenerator generator = new JavaBeanCodeGenerator("/vm/model/java_bean_template.vm",
                projectPath + File.separator + entityName + ".java");
        generator.generate(modelVar);
    }

    private void genVO(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String voName = NamesUtils.entityName2VOName(entityName);
        String queryVoName = NamesUtils.entityName2QueryVOName(entityName);
        String daoModuleName = entityName;

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-domain";
        FileUtils.createDirectory(daoModulePath);

        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);

        //Package
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.VO_PACKAGE_VARIABLE, "org.smr.ministore.vo.outbound"  );
        modelVar.put(CodeConst.QUERY_VO_PACKAGE_VARIABLE, "org.smr.ministore.vo.inbound");

        //Java Bean
        modelVar.put(CodeConst.JAVA_VO_NAME_VARIABLE, voName);
        modelVar.put(CodeConst.JAVA_QUERY_VO_NAME_VARIABLE, queryVoName);

        //Table
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);

        //Project
        modelVar.put(CodeConst.PROJECT_NAME, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, ed.getEntityProterties());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        // gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/model/pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

        // gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        //创建VO 目录
        String voSrcDir = MapUtils.getString(modelVar, CodeConst.VO_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + voSrcDir);

        //VO
        JavaBeanCodeGenerator voSrcGenerator = new JavaBeanCodeGenerator("/vm/model/java_vo_template.vm",
                javaSrcDir + File.separator + voSrcDir + File.separator + voName + ".java");
        voSrcGenerator.generate(modelVar);


        //创建queryVO 目录
        FileUtils.createDirectory(javaSrcDir + File.separator + voSrcDir+ File.separator + "inbound");
         //QueryVO
        JavaBeanCodeGenerator queryVOsrcGenerator = new JavaBeanCodeGenerator("/vm/model/java_query_vo_template.vm",
                javaSrcDir + File.separator + voSrcDir + File.separator + "inbound"+ File.separator + queryVoName + ".java");
        queryVOsrcGenerator.generate(modelVar);


    }


    private List<TableMeta> getColumnConf(String tableName, String entityName, String tableSchema) {

        List<TableMeta> tableMetaList = tableMeteService.findColumn(tableName, tableSchema);
        for (TableMeta tableMeta : tableMetaList) {

            String columnName = tableMeta.getColumnName();
            String entityPropertyName = NamesUtils.columnName2PropertyName(columnName);
            tableMeta.setPropertyName(entityPropertyName);

            tableMeta.setEntityName(entityName);
            String dataType = tableMeta.getDataType().toUpperCase();
            String javaType = ColumnTypeEnum.getJavaTypeEnumByDBType(dataType);

            String methodName = NamesUtils.tableName2EntityName(entityPropertyName);
            tableMeta.setMethodName(methodName);
            tableMeta.setJavaType(javaType);

        }

        return tableMetaList;

    }


    private List<TableMeta> getColumnConf(String tableName, String entityName) {

        String tableSchema = "auth_center";
        List<TableMeta> tableMetaList = tableMeteService.findColumn(tableName, tableSchema);
        for (TableMeta tableMeta : tableMetaList) {

            String columnName = tableMeta.getColumnName();
            String entityPropertyName = NamesUtils.columnName2PropertyName(columnName);
            tableMeta.setPropertyName(entityPropertyName);

            tableMeta.setEntityName(entityName);
            String dataType = tableMeta.getDataType().toUpperCase();
            String javaType = ColumnTypeEnum.getJavaTypeEnumByDBType(dataType);

            String methodName = NamesUtils.tableName2EntityName(entityPropertyName);
            tableMeta.setMethodName(methodName);
            tableMeta.setJavaType(javaType);

        }

        return tableMetaList;

    }


    @ResponseBody
    @RequestMapping("genMapper")
    public void genMapperCode() {

        String tableName = "t_organ_info";
        String entityName = NamesUtils.tableName2EntityName(tableName);
        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);

        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, "auth_center");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);

        JavaBeanCodeGenerator generator = new JavaBeanCodeGenerator("/vm/dao/mapper_xml_template.vm",
                projectPath + File.separator + entityName + "Mapper.xml");
        generator.generate(modelVar);
    }

    @ResponseBody
    @RequestMapping("genJavaFile")
    public void genDaoCode() {

        String tableName = "t_organ_info";
        String entityName = NamesUtils.tableName2EntityName(tableName);

        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);

        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, "auth_center");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);


        JavaBeanCodeGenerator generator = new JavaBeanCodeGenerator("/vm/dao/dao_template.vm",
                projectPath + File.separator + entityName + "Dao.java");
        generator.generate(modelVar);
    }

    @ResponseBody
    @RequestMapping("getProj")
    public void createProject(String projectName) {

        String projectDir = projectPath;

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //TODO pom.xml

        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);


        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, "auth");
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.PROJECT_MODULE_LIST_VARIABLE, module.getEntityDefineList());
        modelVar.put(CodeConst.PROJECT_NAME, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/project/ddd_pom_xml_template.vm",
                projectNamePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

    }

    @RequestMapping("")
    public void genProject(String projectName, String projectPath) {
        String projectDir = projectPath;
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

    }


    @ResponseBody
    @RequestMapping("genInfrastructure")
    public void genInfrastructure(EntityDefine ed, String projectName, String projectPath) {

        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String projectDir = projectPath;
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-infrastructure";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, ed.getName());
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, ed.getTableName());
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/infrastructure/infrastructure_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);
    }


    @ResponseBody
    @RequestMapping("genCommon")
    public void genCommon(EntityDefine ed, String projectName, String projectPath) {

        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String projectDir = projectPath;
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-common";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, ed.getName());
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, ed.getTableName());
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/common/common_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);
    }


    @ResponseBody
    @RequestMapping("genRepository")
    public void genRepository(EntityDefine ed, String projectName, String projectPath) {

        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String projectDir = projectPath;
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-repository";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, ed.getName());
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, ed.getTableName());
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/dao/respository_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.DAO_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/dao/dao_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Mapper.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources mapper
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);

        String mapperDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper";
        FileUtils.createDirectory(mapperDir);

        JavaBeanCodeGenerator mapperGenerator = new JavaBeanCodeGenerator("/vm/dao/mapper_xml_template.vm",
                mapperDir + File.separator + entityName + "Mapper.xml");
        mapperGenerator.generate(modelVar);
    }


    @ResponseBody
    @RequestMapping("genDao")
    public void genDao(EntityDefine ed, String projectName, String projectPath) {

        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String projectDir = projectPath;
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + daoModuleName + "-dao";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, ed.getName());
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, ed.getTableName());
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        // gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/dao/pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.DAO_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/dao/dao_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Mapper.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources mapper
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);

        String mapperDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper";
        FileUtils.createDirectory(mapperDir);

        JavaBeanCodeGenerator mapperGenerator = new JavaBeanCodeGenerator("/vm/dao/mapper_xml_template.vm",
                mapperDir + File.separator + entityName + "Mapper.xml");
        mapperGenerator.generate(modelVar);
    }


    @ResponseBody
    @RequestMapping("getService")
    public void getService(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String tableName = ed.getTableName();
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + daoModuleName + "-service";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/service/pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.SERVICE_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/service/service_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Service.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);


    }


    @ResponseBody
    @RequestMapping("getDDDService")
    public void getDDDService(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String tableName = ed.getTableName();
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-service";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/service/ddd_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.SERVICE_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/service/service_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Service.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);


    }


    @ResponseBody
    @RequestMapping("getDDDRepository")
    public void getDDDRepository(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String daoModuleName = ed.getName();
        String entityName = ed.getName();
        String tableName = ed.getTableName();
        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-service";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.REPOSITORY_PACKAGE_VARIABLE, "org.smr.ministore.repository");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/service/ddd_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.REPOSITORY_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/service/repository_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Repository.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);


    }


    @ResponseBody
    @RequestMapping("genServiceImpl")
    public void genServiceImpl(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + daoModuleName + "-service-implement";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/serviceImpl/service_implement_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/serviceImpl/service_implement_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "ServiceImpl.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);
    }


    @ResponseBody
    @RequestMapping("genDDDServiceImpl")
    public void genDDDServiceImpl(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-service-impl";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/serviceImpl/ddd_service_implement_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/serviceImpl/service_implement_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "ServiceImpl.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);
    }



    @ResponseBody
    @RequestMapping("genDDDRepositoryImpl")
    public void genDDDRepositoryImpl(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-service-impl";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.REPOSITORY_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.repository.impl");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        //gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/serviceImpl/ddd_service_implement_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //gen  dao src main/java
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.REPOSITORY_IMPL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/serviceImpl/repository_implement_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "RepositoryImpl.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);
    }




    @ResponseBody
    @RequestMapping("genFacade")
    public void genFacade(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + daoModuleName + "-service-Facade";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/facade/service_facade_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/facade/service_facade_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "facade.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);
    }


    @ResponseBody
    @RequestMapping("genDDDFacade")
    public void genDDDFacade(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-service-facade";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/facade/ddd_service_facade_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/facade/service_facade_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Facade.java");
        srcGenerator.generate(modelVar);

        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);
    }


    @ResponseBody
    @RequestMapping("genDDDMicroService")
    public void genDDDMicroService(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();
        String urlParts = NamesUtils.tableName2UrlParts(tableName);

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-micro-service";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);
        Map<String, Object> modelVar = new HashMap<>();

        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.URL_PARTS_VARIABLE, urlParts);

        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.MODULE_DEFINE, module.getName());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/micro/ddd_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/micro/micro_service_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "MicroService.java");
        srcGenerator.generate(modelVar);

        JavaBeanCodeGenerator appGenerator = new JavaBeanCodeGenerator("/vm/micro/application_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "MicroApplication.java");
        appGenerator.generate(modelVar);


        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);


        //TODO yml
        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/application_yml_template.vm",
                resourcesDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);
        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_yml_template.vm",
                resourcesDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);

        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_dev_yml_template.vm",
                resourcesDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);

        //TODO  client

    }


    @ResponseBody
    @RequestMapping("genMicroService")
    public void genMicroService(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + daoModuleName + "-micro-service";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);
        Map<String, Object> modelVar = new HashMap<>();

        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.MODULE_DEFINE, module.getName());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/micro/pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/micro/micro_service_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "MicroService.java");
        srcGenerator.generate(modelVar);

        JavaBeanCodeGenerator appGenerator = new JavaBeanCodeGenerator("/vm/micro/application_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "MicroApplication.java");
        appGenerator.generate(modelVar);


        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);


        //TODO yml
        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/application_yml_template.vm",
                resourcesDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);
        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_yml_template.vm",
                resourcesDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);

        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_dev_yml_template.vm",
                resourcesDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);

        //TODO  client

    }


    private void genDDDMicroServiceClient(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String daoModuleName = entityName;
        String urlParts = NamesUtils.tableName2UrlParts(tableName);

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);


        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-micro-service-client";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);
        Map<String, Object> modelVar = new HashMap<>();


        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.URL_PARTS_VARIABLE, urlParts);

        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.MODULE_DEFINE, module.getName());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE, "org.smr.ministore.micro.client");


        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));


        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/client/ddd_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/client/micro_service_client_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + "Feign" + entityName + "VOMicroServiceClient.java");
        srcGenerator.generate(modelVar);


        JavaBeanCodeGenerator hystrixServiceSrcGenerator = new JavaBeanCodeGenerator("/vm/client/HystrixServiceClientFactory_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + "Hystrix" + entityName + "VOClientFactory.java");
        hystrixServiceSrcGenerator.generate(modelVar);


        JavaBeanCodeGenerator feignSrcGenerator = new JavaBeanCodeGenerator("/vm/client/ServiceFeignClientWithFactory_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "VOFeignClientWithFactory.java");
        feignSrcGenerator.generate(modelVar);


        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);

        //TODO yml
        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/application_yml_template.vm",
                resourcesDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);
        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_yml_template.vm",
                resourcesDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);

        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_dev_yml_template.vm",
                resourcesDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);


    }


    private void genDDDServiceClient(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String daoModuleName = entityName;
        String urlParts = NamesUtils.tableName2UrlParts(tableName);
        String voName = NamesUtils.entityName2VOName(entityName);
        String queryVoName = NamesUtils.entityName2QueryVOName(entityName);


        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);


        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-service-client";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);
        Map<String, Object> modelVar = new HashMap<>();


        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.URL_PARTS_VARIABLE, urlParts);
        modelVar.put(CodeConst.QUERY_VO_PACKAGE_VARIABLE, "org.smr.ministore.vo.inbound");
        modelVar.put(CodeConst.VO_PACKAGE_VARIABLE, "org.smr.ministore.vo");





        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.JAVA_VO_NAME_VARIABLE, voName);
        modelVar.put(CodeConst.JAVA_QUERY_VO_NAME_VARIABLE, queryVoName);

        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.MODULE_DEFINE, module.getName());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE, "org.smr.ministore.micro.client");


        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/serviceClient/ddd_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/serviceClient/sdk_service_client_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + "Feign" + entityName + "VOMicroServiceClient.java");
        srcGenerator.generate(modelVar);


        JavaBeanCodeGenerator hystrixServiceSrcGenerator = new JavaBeanCodeGenerator("/vm/serviceClient/HystrixSDKServiceClientFactory_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + "Hystrix" + entityName + "VOClientFactory.java");
        hystrixServiceSrcGenerator.generate(modelVar);


        JavaBeanCodeGenerator feignSrcGenerator = new JavaBeanCodeGenerator("/vm/serviceClient/SDKServiceFeignClientWithFactory_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "VOFeignClientWithFactory.java");
        feignSrcGenerator.generate(modelVar);


        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);

        //TODO yml
        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/application_yml_template.vm",
                resourcesDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);
        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_yml_template.vm",
                resourcesDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);

        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_dev_yml_template.vm",
                resourcesDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);


    }


    private void genMicroServiceClient(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String daoModuleName = entityName;

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);


        //创建
        String daoModulePath = projectNamePath + File.separator + daoModuleName + "-micro-service-client";
        FileUtils.createDirectory(daoModulePath);

        List<TableMeta> tableMetaList = getColumnConf(tableName, entityName);
        Map<String, Object> modelVar = new HashMap<>();


        Module module = (Module) CodeConst.get(CodeConst.MODULE_DEFINE);
        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");
        modelVar.put(CodeConst.MODULE_DEFINE, module.getName());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE, "org.smr.ministore.micro.client");


        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));


        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/client/pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/client/micro_service_client_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + "Feign" + entityName + "MicroServiceClient.java");
        srcGenerator.generate(modelVar);


        JavaBeanCodeGenerator hystrixServiceSrcGenerator = new JavaBeanCodeGenerator("/vm/client/HystrixServiceClientFactory_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + "Hystrix" + entityName + "ClientFactory.java");
        hystrixServiceSrcGenerator.generate(modelVar);


        JavaBeanCodeGenerator feignSrcGenerator = new JavaBeanCodeGenerator("/vm/client/ServiceFeignClientWithFactory_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "FeignClientWithFactory.java");
        feignSrcGenerator.generate(modelVar);


        //TODO gen resources
        String resourcesDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        FileUtils.createDirectory(resourcesDir);

        //TODO yml
        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/application_yml_template.vm",
                resourcesDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);
        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_yml_template.vm",
                resourcesDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);

        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/micro/bootstrap_dev_yml_template.vm",
                resourcesDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);


    }

    @ResponseBody
    @RequestMapping("genModel")
    public void genModel(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String daoModuleName = entityName;

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-model";
        FileUtils.createDirectory(daoModulePath);

        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.PROJECT_NAME, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, ed.getEntityProterties());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));


        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/model/pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MODEL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/model/java_bean_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + ".java");
        srcGenerator.generate(modelVar);

    }


    @ResponseBody
    @RequestMapping("genDomain")
    public void genDomain(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String daoModuleName = entityName;

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-domain";
        FileUtils.createDirectory(daoModulePath);

        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.PROJECT_NAME, CodeConst.get(CodeConst.PROJECT_NAME));
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, ed.getEntityProterties());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));


        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/model/ddd_pom_xml_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);

        //TODO gen  dao src code
        String javaSrcDir = daoModulePath + File.separator + "src" + File.separator + "main" + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.MODEL_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/model/java_bean_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + ".java");
        srcGenerator.generate(modelVar);

    }


    @ResponseBody
    @RequestMapping("genController")
    public void genController(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + entityName + "-controller";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.CONTROLLER_PACKAGE_VARIABLE, "org.smr.ministore.controller");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));

        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/web/module_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        String mainDir = daoModulePath + File.separator + "src" + File.separator + "main";

        //TODO gen  dao src code
        String javaSrcDir = mainDir + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.CONTROLLER_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/web/controller_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Controller.java");
        srcGenerator.generate(modelVar);


        JavaBeanCodeGenerator applicationJavaGenerator = new JavaBeanCodeGenerator("/vm/web/module_applicationStartup_java.vm",
                javaSrcDir + File.separator + "org" + File.separator + "smr" + File.separator + entityName + "Application.java");
        applicationJavaGenerator.generate(modelVar);


        String configurationDir = mainDir + File.separator + "resources";
        FileUtils.createDirectory(configurationDir);


        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/web/module_application_yml_template.vm",
                configurationDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);


        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/web/module_bootstrap_yml_template.vm",
                configurationDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);


        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/web/module_bootstrap_dev_yml_template.vm",
                configurationDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);


    }


    @ResponseBody
    @RequestMapping("genDDDController")
    public void genDDDController(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = ed.getName();
        String daoModuleName = ed.getName();
        String urlParts = NamesUtils.tableName2UrlParts(tableName);

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-application";
        FileUtils.createDirectory(daoModulePath);


        List<TableMeta> tableMetaList = ed.getEntityProterties();
        Map<String, Object> modelVar = new HashMap<>();

        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, daoModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.CONTROLLER_PACKAGE_VARIABLE, "org.smr.ministore.controller");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.URL_PARTS_VARIABLE, urlParts);
        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, tableMetaList);
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));

        modelVar.put(CodeConst.JAVA_BEAN_CAMEL_NAME_VARIABLE, StringUtils.lowerFirstCase(entityName));
        modelVar.put(CodeConst.MICRO_SERVICE_CLIENT_PACKAGE_VARIABLE, "org.smr.ministore.micro.client");

        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");


        //TODO gen pom
        JavaBeanCodeGenerator pomGenerator = new JavaBeanCodeGenerator("/vm/web/ddd_module_pom_template.vm",
                daoModulePath + File.separator + "pom.xml");
        pomGenerator.generate(modelVar);


        String mainDir = daoModulePath + File.separator + "src" + File.separator + "main";

        //TODO gen  dao src code
        String javaSrcDir = mainDir + File.separator + "java";
        FileUtils.createDirectory(javaSrcDir);

        String srcDir = MapUtils.getString(modelVar, CodeConst.CONTROLLER_PACKAGE_VARIABLE).replace(".", File.separator);
        FileUtils.createDirectory(javaSrcDir + File.separator + srcDir);

        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/web/controller_template.vm",
                javaSrcDir + File.separator + srcDir + File.separator + entityName + "Controller.java");
        srcGenerator.generate(modelVar);


        JavaBeanCodeGenerator applicationJavaGenerator = new JavaBeanCodeGenerator("/vm/web/module_applicationStartup_java.vm",
                javaSrcDir + File.separator + "org" + File.separator + "smr" + File.separator + entityName + "Application.java");
        applicationJavaGenerator.generate(modelVar);


        String configurationDir = mainDir + File.separator + "resources";
        FileUtils.createDirectory(configurationDir);


        JavaBeanCodeGenerator applicationYmlGenerator = new JavaBeanCodeGenerator("/vm/web/module_application_yml_template.vm",
                configurationDir + File.separator + "application.yml");
        applicationYmlGenerator.generate(modelVar);


        JavaBeanCodeGenerator bootstrapYmlGenerator = new JavaBeanCodeGenerator("/vm/web/module_bootstrap_yml_template.vm",
                configurationDir + File.separator + "bootstrap.yml");
        bootstrapYmlGenerator.generate(modelVar);


        JavaBeanCodeGenerator bootstrapDevYmlGenerator = new JavaBeanCodeGenerator("/vm/web/module_bootstrap_dev_yml_template.vm",
                configurationDir + File.separator + "bootstrap-dev.yml");
        bootstrapDevYmlGenerator.generate(modelVar);


    }


    @ResponseBody
    @RequestMapping("genPage")
    public void genPage(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String pageModuleName = entityName;

        String urlParts = NamesUtils.tableName2UrlParts(tableName);

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-page";
        FileUtils.createDirectory(daoModulePath);

        Map<String, Object> modelVar = new HashMap<>();


        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, pageModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.URL_PARTS_VARIABLE, urlParts);

        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, ed.getEntityProterties());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));


        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        //gen js
        JavaBeanCodeGenerator jsFileGenerator = new JavaBeanCodeGenerator("/vm/page/vue_javascript_api_template.vm",
                daoModulePath + File.separator + entityName + ".js");
        jsFileGenerator.generate(modelVar);

        //gen vue
        JavaBeanCodeGenerator srcGenerator = new JavaBeanCodeGenerator("/vm/page/vue_page_template.vm",
                daoModulePath + File.separator + entityName + ".vue");
        srcGenerator.generate(modelVar);


        //gen list.vue
        JavaBeanCodeGenerator listGenerator = new JavaBeanCodeGenerator("/vm/page/vue_list_template.vm",
                daoModulePath + File.separator + entityName + "List.vue");
        listGenerator.generate(modelVar);

        //gen list.vue
        JavaBeanCodeGenerator detailGenerator = new JavaBeanCodeGenerator("/vm/page/vue_detail_template.vm",
                daoModulePath + File.separator + entityName + "Detail.vue");
        detailGenerator.generate(modelVar);


    }


    @ResponseBody
    @RequestMapping("genVue3Page")
    public void genVue3Page(EntityDefine ed, String projectName, String projectPath) {

        String projectDir = projectPath;
        String tableName = ed.getTableName();
        String entityName = NamesUtils.tableName2EntityName(tableName);
        String pageModuleName = entityName;

        String urlParts = NamesUtils.tableName2UrlParts(tableName);

        String projectNamePath = projectDir + File.separator + projectName;
        FileUtils.createDirectory(projectNamePath);

        //创建
        String daoModulePath = projectNamePath + File.separator + projectName + "-page";
        FileUtils.createDirectory(daoModulePath);

        Map<String, Object> modelVar = new HashMap<>();


        modelVar.put(CodeConst.MODULE_NAME_VARIABLE, pageModuleName);
        modelVar.put(CodeConst.SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.service");
        modelVar.put(CodeConst.MICRO_SERVICE_PACKAGE_VARIABLE, "org.smr.ministore.micro");
        modelVar.put(CodeConst.SERVICE_IMPL_PACKAGE_VARIABLE, "org.smr.ministore.service.impl");
        modelVar.put(CodeConst.DAO_PACKAGE_VARIABLE, "org.smr.ministore.dao");
        modelVar.put(CodeConst.MODEL_PACKAGE_VARIABLE, "org.smr.ministore.entities");
        modelVar.put(CodeConst.JAVA_BEAN_NAME_VARIABLE, entityName);
        modelVar.put(CodeConst.TABLE_NAME_VARIABLE, tableName);
        modelVar.put(CodeConst.URL_PARTS_VARIABLE, urlParts);

        modelVar.put(CodeConst.MODEL_PROPERTY_VARIABLE, ed.getEntityProterties());
        modelVar.put(CodeConst.PROJECT_MODEL_VARIABLE, CodeConst.get(CodeConst.PROJECT_NAME));


        modelVar.put(CodeConst.PROJECT_GROUP_ID, "org.smr");

        //gen js
        JavaBeanCodeGenerator jsFileGenerator = new JavaBeanCodeGenerator("/vm/page/ts_vue_javascript_api_template.vm",
                daoModulePath + File.separator + entityName + "Api.ts");
        jsFileGenerator.generate(modelVar);

        //gen vue
        JavaBeanCodeGenerator typesGenerator = new JavaBeanCodeGenerator("/vm/page/ts_vue_types_template.vm",
                daoModulePath + File.separator + entityName + "Types.ts");
        typesGenerator.generate(modelVar);


        //gen list.vue
        JavaBeanCodeGenerator listGenerator = new JavaBeanCodeGenerator("/vm/page/ts_vue_list_template.vm",
                daoModulePath + File.separator + entityName + "Index.vue");
        listGenerator.generate(modelVar);

        //gen editor.vue
        JavaBeanCodeGenerator detailGenerator = new JavaBeanCodeGenerator("/vm/page/ts_vue_detail_template.vm",
                daoModulePath + File.separator + entityName + "DialogEditor.vue");
        detailGenerator.generate(modelVar);

        //gen editor.vue
        JavaBeanCodeGenerator drawerGenerator = new JavaBeanCodeGenerator("/vm/page/ts_vue_drawer_template.vm",
                daoModulePath + File.separator + entityName + "DrawerEditor.vue");
        drawerGenerator.generate(modelVar);

    }



}
